
export default{
    data(){
        return {
            //设置默认的分享参数
            //如果页面不设置share，就触发这个默认的分享
			pid : 0,
            share:{
                title:'',
                path:'/pages/index/index',
                imageUrl:'',
                desc:'',
                content:''
            },
        }
    },
	onShareTimeline() {
		let uid = this.vuex?.userInfo?.id || 0;
		let str = this.share.path;
		if(uid){
			let index = this.share.path.indexOf('?pid=');
			let index1 = this.share.path.indexOf('&pid=');
			if (index == -1 && index1 == -1) { 
				let index2 = this.share.path.indexOf('?');
				 if(index2 == -1){
					   str += '?pid='+uid;
				 }else{
					   str += '&pid='+uid; 
				 }
				 this.share.path = str;
			} 
		}
		return {
		    title:this.share.title,
		    path:this.share.path,
		    imageUrl:this.share.imageUrl,
		    desc:this.share.desc,
		    content:this.share.content,
		    success(res){
		        uni.showToast({
		            title:'分享成功'
		        })
		    },
		    fail(res){
		        uni.showToast({
		            title:'分享失败',
		            icon:'none'
		        })
		    }
		}
	},
    onShareAppMessage(res) {
		let uid = this.vuex?.userInfo?.id || 0;
		 let str = this.share.path;
		if(uid){
			let index = this.share.path.indexOf('?pid=');
			let index1 = this.share.path.indexOf('&pid=');
			if (index == -1 && index1 == -1) { 
				let index2 = this.share.path.indexOf('?');
				 if(index2 == -1){
					   str += '?pid='+uid;
				 }else{
					   str += '&pid='+uid; 
				 }
				 this.share.path = str;
			} 
		}
        return {
            title:this.share.title,
            path:this.share.path,
            imageUrl:this.share.imageUrl,
            desc:this.share.desc,
            content:this.share.content,
            success(res){
                uni.showToast({
                    title:'分享成功'
                })
            },
            fail(res){
                uni.showToast({
                    title:'分享失败',
                    icon:'none'
                })
            }
        }
    }
}
